#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxn=110;
long long f[maxn][maxn];
int a[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=n-2;i>=1;i--)
	{
		f[i][i+2]=a[i]*a[i+1]*a[i+2];
		for(int j=i+3;j<=n;j++)
		{
			f[i][j]=1LL<<60;
			for(int k=i+1;k<=j-1;k++)
				f[i][j]=min(f[i][j],f[i][k]+f[k][j]+a[i]*a[j]*a[k]);
		}
	}
	cout<<f[1][n]<<endl;
	return 0;
}
